<?php
    $url = new Url(); 
    $forder_upload = "ringBack";  
    $link_avatar = Yii::app()->params["urlImages"] . "upload_avatar_category_ring.php?forder_upload=" . $forder_upload;    
    $link_url = Yii::app()->params["urlImages"] . "upload_base.php?forder_upload=".$forder_upload;
    $singId = ARingBackSinger::getAllNameSinger();
    $arr_status = LoadConfig::$status;
?>
<link rel="stylesheet" href="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/css/swfupload.css" type="text/css" />
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/swfupload.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/swfupload.queue.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/fileprogress.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['urlImages']; ?>lib_upload/js/handlers.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['tiny_url_cp'];?>/js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->params['static_url_cp'];?>/js/tinymce_submit.js"></script>   
<script type="text/javascript" src="<?php echo Yii::app()->params['static_url_cp'];?>/js/jquery-ui.min.js"></script>   
<script type="text/javascript">
    window.onload = function() {
        var configUploadData = {
            flash_url:"<?php echo Yii::app()->params["urlImages"];?>lib_upload/js/swfupload.swf",
            create_date:0,
            button_image_url:"<?php echo Yii::app()->params["urlImages"];?>lib_upload/images/buttonUpload.png",
            upload_url: "<?php echo $link_avatar;?>", 
            file_types: "*.jpg;*.jpeg;*.png;*.gif", 
            file_upload_limit : 20, 
            file_queue_limit : 1, 
            debug : false
        }
        configUpload(configUploadData);    
    }; 
    function uploadResponse(serverData){  
        try {
            $("#txtFileName").val(""); 
            var response = $.parseJSON(serverData); // eval( "(" + serverData + ")" );      
            if(response.code==404){
                alert(response.message);return false;
            }  
            var filename = response.filename;    
            var path = response.path;
            var message = response.message;
            var code = response.code;
            var extension = response.extension;
            var filesize = response.filesize;
            $("#picture").val(filename);
            $("#show_pic").html('<img src="<?php echo Yii::app()->params["urlImages"].$forder_upload.'/';?>'+path +'/'+ filename +'">')
        } catch (e) {

        };
    }
    function ajaxSaveIcon(){ 
        var title = $("#title").val(); 
        var picture = $("#picture").val();     
        var position = $("#position").val();     
        var strUrl = "<?=$url->createUrl("ringBack/ajaxSaveIcon") ?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                title:title,
                picture:picture,
                position:position,
            },
            success: function(msg){
                if(msg == 1){
                    alert('Thêm thành công');
                    window.location = '<?php echo $url->createUrl("ringBack/category")?>';
                }else{
                    $("#show_error").html(msg);
                }
            },
            beforeSend:function(){
                $("#button_save").attr("disabled","disabled");
            },
            complete:function(){
                $("#button_save").removeAttr("disabled"); 
            }          
        });
    }
</script>  
<div id="container">
    <div class="main clearfix">
        <div class="Tabs clearfix">
            <ul class="clearfix">
                <li><a href="<?php echo Url::createUrl('ringBack/index');?>"><span>Quản trị nhạc chờ</span></a></li>
                <li><a href="<?php echo Url::createUrl('ringBack/singer');?>"><span>Quản trị ca sĩ/nhóm nhạc</span></a></li>
                <li><a class="active" href="<?php echo Url::createUrl('ringBack/category');?>"><span>Quản trị thể loại nhạc</span></a></li>
            </ul>                
        </div>
        <div class="box clearfix bottom30">
            <ul class="form4"> 
                <li class="clearfix"><label><strong>Tên danh mục</strong> <span class="clred"></span>:</label>
                    <div class="filltext">
                        <input type="text" style="width:331px;margin-right:10px" value="" id="title">
                    </div>
                </li>
                <li class="clearfix"><label><strong>Icon thể loại </strong>:</label>
                    <div class="filltext">
                        <p>
                            <input type="hidden" id="txtFileName" readonly="readonly"/>
                            <input type="text" id="urlFile" style="border:1px solid #DFDFDF; width: 200px;">                            
                            <span id="spanButtonPlaceHolder"></span>
                        </p>
                        <br/>
                        <div class="fieldset flash" id="fsUploadProgress">
                            <span class="legend">File upload</span>
                        </div>
                        <input type="hidden" id="picture" value=""/>
                        <p id="show_pic"></p>
                    </div>
                </li>
                <li class="clearfix">
                    <label><strong>Vị trí</strong> <span class="clred"></span>:</label>
                    <div class="filltext">
                        <input type="text" style="width:331px;margin-right:10px" value="" id="position"> (Thấp lên trên)
                    </div>
                </li>
                <li class="clearfix"><label>&nbsp;</label>
                    <div class="filltext">
                        <input id="button_save"  type="button" value=" Thêm mới " class="btn-bigblue" onclick="ajaxSaveIcon();">&nbsp;
                        &nbsp;<input onclick="history.go(-1)" type="button" value=" Làm lại " class="btn-bigblue"> 
                    </div>
                </li>   
                <li class="clearfix"><label>&nbsp;</label>
                    <div class="filltext" style="color: red;" id="show_error"></div>
                </li> 
            </ul>    
        </div>
    </div>
    <!-- End main-->
</div>
